package com.xnyzc.lhy.order.service.impl.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ecwid.consul.v1.agent.model.Check;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.order.entity.user.OaDUser;
import com.xnyzc.lhy.order.mapper.user.OaDUserMapper;
import com.xnyzc.lhy.order.service.user.IOaDUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 司机用户-信息表 服务实现类
 * </p>
 *
 * @author bin
 * @since 2019-07-23
 */
@Slf4j
@Service
public class IOaDUserServiceImpl extends ServiceImpl<OaDUserMapper, OaDUser> implements IOaDUserService {

    @Autowired
    private OaDUserMapper oaDUserMapper;

    @Override
    public String getDriverPhone(Long driverId) {

        QueryWrapper<OaDUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaDUser.DRIVER_ID, driverId);
        queryWrapper.select(OaDUser.DRIVER_PHONE);
        OaDUser oaDUser = null;
        try {
            oaDUser = oaDUserMapper.selectOne(queryWrapper);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw PangException.create(EErrorCode.unDUserInfo);
        }

        if (CheckUtil.objIsEmpty(oaDUser)) {
            throw PangException.create(EErrorCode.unDUserInfo);
        }

        return oaDUser.getDriverPhone();
    }
}
